 # -*- coding:utf-8 -*-
#! python3

from facecat import *
import websocket
#pip install websocket-client 
import json
try:
    import thread
except ImportError:
    import _thread as thread

gPaint = FCPaint() #创建绘图对象
gPaint.defaultUIStyle = "dark"

#消息循环
def WndProc(hwnd,msg,wParam,lParam):
	return WndProcDefault(gPaint,hwnd,msg,wParam,lParam)

#创建窗体
createMainWindow(gPaint, "facecat-py", WndProc)
#创建图层
div = FCDiv()
div.paint = gPaint
#填充满整个布局 
div.dock = "fill"
#添加到视图
addView(div, gPaint)

updateViewDefault(gPaint.views)
showWindow(gPaint)

#WebSocket消息回调
def on_message(ws, message):
	print(message)

#WebSocket错误回调
def on_error(ws, error):
    print(error)

#WebSocket关闭回调
def on_close(ws, close_status_code, close_msg):
    print("closed")

#WebSocket启动回调
def on_open(ws):
    print("start")

#启动WebSocket
def startWebSocket():
	websocket.enableTrace(True)
	ws = websocket.WebSocketApp("",
								on_open=on_open,
								on_message=on_message,
								on_error=on_error,
								on_close=on_close)

	ws.run_forever()


#启动WebSocket
def run(*args):
	startWebSocket()
#开启线程
thread.start_new_thread(run, ())
